package cn.wolfcode.luowowo.website.controller;

import cn.wolfcode.luowowo.scenic.domain.ScenicComment;
import cn.wolfcode.luowowo.scenic.service.IScenicCommentService;
import cn.wolfcode.luowowo.search.service.*;
import cn.wolfcode.luowowo.search.template.*;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/elasticsearch")
public class ElasticsearchController {
    @Reference
    private IScenicCommentService scenicCommentService;


    @Reference
    private IScenicCommentSearchService scenicSearchService;


    @RequestMapping("/init")
    @ResponseBody
    public String init() {

        //===============景点数据初始化===================
        List<ScenicComment> list = scenicCommentService.list();

        for (ScenicComment scenicComment : list) {
            ScenicCommentTemplate scenicCommentTemplate = new ScenicCommentTemplate();

            scenicCommentTemplate.setId(scenicComment.getId());
            scenicCommentTemplate.setScenicId(scenicComment.getScenicId());

            scenicCommentTemplate.setUserId(scenicComment.getUser().getId());
            scenicCommentTemplate.setUsername(scenicComment.getUser().getNickname());
            scenicCommentTemplate.setLevel(scenicComment.getUser().getLevel());
            scenicCommentTemplate.setHeadUrl(scenicComment.getUser().getHeadImgUrl());

            scenicCommentTemplate.setCreateTime(scenicComment.getCreateTime());
            scenicCommentTemplate.setComment(scenicComment.getComment());

            scenicCommentTemplate.setThumbupnum(scenicComment.getThumbupnum());

            scenicCommentTemplate.setImgUrls(scenicComment.getImgUrls());
            scenicCommentTemplate.setPictures(scenicComment.getPictures());

            scenicCommentTemplate.setRank(scenicComment.getRank());

            scenicSearchService.save(scenicCommentTemplate);
        }
        return "ok";
    }

}
